<!DOCTYPE HTML>
<html>
<head>
<include file="Include:meta" />
<title>授权管理-目的地运营集团数据管理平台</title>
<include file="Include:style" />
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text"><if condition="$project['info_id'] neq NULL">商务跟进</if>项目 > [{$project['project_num']}]{$project['project_name']} > 授权管理</div>
	</div>
	<div id="content">
		<include file="Include:project_header" />
		<form method="post" name="number_validate" id="password_validate" novalidate="novalidate">
			<div class="form-main">
				<div class="form-title">授权管理</div>
				<div class="form-table-item">
					<table class="table">
						<tbody>
							<tr class="form-table-header">
								<td width="10%">项目人员</td>
								<td width="30%">授权功能</td>
								<td width="30%">授权周期</td>
								<td width="20%">添加人(日期)</td>
								<if condition="((((get_permission($qs,NULL,3)) and ($project['add_uid'] eq $login_id)) or (get_permission($qs,NULL,2) and (in_array($project['center_id'],$manage_id))) or (get_permission($qs,NULL,1))) or ($project['director_uid'] eq $login_id) or ($project['manager_uid'] eq $login_id)) and ($project['status'] eq 1)">
								<td width="10%">管理</td>
								</if>
							</tr>
							<if condition="$result eq NULL">
							<tr>
								<td class="text-center" <if condition="((((get_permission($qs,NULL,3)) and ($project['add_uid'] eq $login_id)) or (get_permission($qs,NULL,2) and (in_array($project['center_id'],$manage_id))) or (get_permission($qs,NULL,1))) or ($project['director_uid'] eq $login_id) or ($project['manager_uid'] eq $login_id)) and ($project['status'] eq 1) and ($project['gt_status'] neq 1)">colspan="5"<else/>colspan="4"</if>>暂无相关数据</td>
							</tr>
							</if>
							<foreach name="result" item="vo">
								<tr>
									<td>{$vo['user']}</td>
									<td>{$vo['permissions']}</td>
									<td>{$vo['start_date']} 至 <if condition="$vo['end_date'] lt '4000-01-01'">{$vo['end_date']}<else />无限制</if></td>
									<td>{$vo['add_user']}({$vo['add_date']|substr=0,10})</td>
									<if condition="((((get_permission($qs,NULL,3)) and ($project['add_uid'] eq $login_id)) or (get_permission($qs,NULL,2) and (in_array($project['center_id'],$manage_id))) or (get_permission($qs,NULL,1))) or ($project['director_uid'] eq $login_id) or ($project['manager_uid'] eq $login_id)) and ($project['status'] eq 1)">
									<td>
										<a href="javascript:;" class="operate" id="{$vo['id']}" pid="{$vo['pid']}" uid="{$vo['uid']}" data-toggle="tooltip" data-placement="left" title="修改授权周期"><i class="glyphicon glyphicon-wrench"></i></a>
										<if condition="$vo['del'] eq 1">
										<a href="javascript:;" mid="{$vo['id']}" action="delete" data-toggle="tooltip" data-placement="left" title="删除" class="delete ml5"><i class="glyphicon glyphicon-trash"></i></a>
										</if>
									</td>
									</if>
								</tr>
							</foreach>
						</tbody>
					</table>
				</div>
				<div class="form-title">添加授权管理</div>
				<div class="form-item clearfix">
					<div class="item-float" colspan="2">
						<div class="input-label"><span class="asterisk">*</span>项目人员</div>
						<div class="input-item">
							<select name="uid" class="form-control required-selted" autocomplete="off">
								<if condition="$user_list eq NULL">
									<option value="-10" selected>暂无人员</option>
								<else/>
									<option value="-10" selected>请选择</option>
									<foreach name="user_list" item="vo">
										<option value="{$vo['id']}">{$vo['username']}</option>
									</foreach>
								</if>
							</select>
							<span class="error-item">必填项</span>
						</div>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>授权功能</div>
					<div class="input-item sq_box">
						<if condition="$project_function eq NULL">
							<span class="input-prompt"><i class="glyphicon glyphicon-exclamation-sign ml10"></i> 暂无相关功能</span>
						<else/>
							<foreach name="project_function" item="vo">
								<label class="checkbox-inline"><input type="checkbox" class="checkbox" name="p_ids[]" value="{$vo['id']}">{$vo['name1']}</label>
							</foreach>
							<span class="error-item">必填项</span>
						</if>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label">授权周期</div>
					<div class="input-item">
						<input type="text" name="start_date" value="{$today}" class="form-control Wdate w100 required-text" onclick="WdatePicker()" readonly autocomplete="off">
						 至 
						<input type="text" name="end_date" class="form-control Wdate w100 required-text" onclick="WdatePicker({isShowClear:true})" readonly autocomplete="off">
						<span class="input-prompt"><i class="glyphicon glyphicon-exclamation-sign ml10"></i> 结束日期可为空，代表无限制</span>
					</div>
				</div>
				<div class="form-btn-item"><button class="btn submit" type="button">提交</button></div>
			</div>
		</form>
	</div>
</div>
<!--对话框-->
<div class="modal fade" id="myModal-operate">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4>操作提示框</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				<table class="table table-bordered">
					<tr>
						<td class="text-right" width="100"><strong><span class="asterisk">*</span>授权结束日期</strong></td>
						<td>
							<input type="text" name="stop_date" class="form-control Wdate stop_date w100" onclick="WdatePicker()" readonly autocomplete="off">
							<span class="input-prompt"><i class="glyphicon glyphicon-exclamation-sign ml10"></i> 结束日期可为空，代表无限制</span>
							<input type="hidden" name="id">
							<input type="hidden" name="pid">
							<input type="hidden" name="uid">
							<span class="error-item">必填项</span>
						</td>
					</tr>
				</table>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-affirm">确认</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<include file="Include:javascript" />
<script>
$(function(){
	$(".delete").ajaxModal({"title_text":"删除提示框","body_text":"您确定要删除吗？","url":"__APP__/Project/project_auth_ajax","data":{"id":"mid","action":"action"}});
	//提交验证
	$(".submit").on('click',function(){
		var tag = true,
			start = $("[name='start_date']").val(),
			end = $("[name='end_date']").val();
		$("[name='uid']").each(function(){
			var val = $(this).val();
			if(val==-10){
				$(this).nextAll('.error-item').show();
				tag=false;
			}
		})
		if($('.checkbox:checked').length<1){
			$('.sq_box').find('.error-item').show();
			tag=false;
		}
		if(end!=''){
			//前后日期判断
			function compareDate(date1,date2){
				let Y1 = parseInt(date1.substr(0, 4)),
					Y2 = parseInt(date2.substr(0, 4)),
					M1 = parseInt(date1.substr(5, 2)),
					M2 = parseInt(date2.substr(5, 2)),
					D1 = parseInt(date1.substr(8, 2)),
					D2 = parseInt(date2.substr(8, 2));
				let a = Y1 < Y2,
					b = Y1 == Y2 && M1 < M2,
					c = Y1 == Y2 && M1 == M2 && D1 < D2;

				if (a || b || c) {
					return true;
				} else {
					return false;
				}
			}
			if(compareDate(end,start)){
				defeated_alert('结束日期不能早于开始日期');
				tag = false;
			}
		}
		if(tag){
			var communicate_add = 'add',
				pid = "{$project['id']}";
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:$("[name='number_validate']").serialize()+"&action="+communicate_add+"&pid="+pid,
				url:"__APP__/Project/project_auth_ajax",
				success:function(data){
					success_pop(data.status,data.msg);
				}
			});    
		}
	});
	//隐藏错误提示
	$("[name='uid']").change(function(){
		$(this).nextAll('.error-item').hide();
	})
	$("[name='p_ids[]']").click(function(){
		$(this).parent().siblings(".error-item").hide();
	});
	//项目功能-->添加修改授权周期 designed by:chenyan 2018-08-20
	//修改授权周期
	$(".operate").on("click",function(){
		var id = $(this).attr("id"),
			pid = $(this).attr("pid"),
			uid = $(this).attr("uid");
		$("[name='id']").val(id);
		$("[name='pid']").val(pid);
		$("[name='uid']").val(uid);
		$("#myModal-operate").removeClass('fade');
		$("#myModal-operate").show();
	});
	//关闭按钮
	$(".fa-times,.btn-default").on("click",function(){
		$("#myModal-operate").addClass('fade');
		$("#myModal-operate").hide();
	});
	//确认操作
	$("#myModal-operate").find(".btn-affirm").on("click",function(){
		var tag = true,
		modal = $("#myModal-operate");
		end = $("[name='stop_date']").val();
		if(end==''){
			end = '4000-01-01';
		}
		if(tag){
			var id = $("[name='id']").val(),
			pid = $("[name='pid']").val(),
			uid = $("[name='uid']").val();
			modal.hide();
			$.ajax({
				type:"POST",
				asnyc:false,
				dataType:"json",
				data:{"id":id,"pid":pid,"uid":uid,"end_date":end},
				url:"__APP__/Project/project_auth_date",
				success:function(data){
					success_pop(data['status'],data['msg']);
				}
			});
		}
	});
})
</script>
</body>
</html>